package br3akr.DeadlyDinnerParty.Server.Actions;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

import br3akr.DeadlyDinnerParty.Server.Engine.Session;

public class DanceAction extends Action {
	private static final int START  = 1;
	private static final int VERIFY = 2;
	private static final int REALLY_VERIFY = 3;
	private static final int HOW_DANCE = 4;
	private int curStep;
	private ActionResponse actionResponse;
	public static final Set<String> keywords;
	static
	{
		Set<String>tempKeywords = new HashSet<String>();
		tempKeywords.add("Dance");
		keywords = Collections.unmodifiableSet(tempKeywords);
	}

    public DanceAction() {
        super("Dance", false);
		curStep = 1;
    }
    
    public ActionResponse doAction(String action, Session session) {
		StringTokenizer st = new StringTokenizer(action);
		int firstTokenLength = st.nextToken().length();
        actionResponse = new ActionResponse();
        actionResponse.addAffectedArea(session.getCharacter().getLocation());
        actionResponse.setActingCharacter(session.getCharacter());
        
		if ((action).trim().length() > firstTokenLength) {
			curStep = HOW_DANCE;
			action = action.substring(firstTokenLength + 1);
		}
		
		switch (curStep) {
			case START:
                actionResponse.setActingCharacterDescription("Are you sure?");
				curStep = VERIFY;
				break;
			case VERIFY:
				if (action.equalsIgnoreCase("Y") || action.equalsIgnoreCase("Yes")) {
                    actionResponse.setActingCharacterDescription("No dancing then, well that's good!");
				} else {
                    actionResponse.setActingCharacterDescription("Are you really sure?");
					curStep = REALLY_VERIFY;
				}
				break;
			case REALLY_VERIFY:
				if (action.equalsIgnoreCase("Y") || action.equalsIgnoreCase("Yes")) {
                    actionResponse.setActingCharacterDescription("Whew, I really thought you were gonna do it!");
				} else {
                    actionResponse.setActingCharacterDescription("Describe your dance!");
					curStep = HOW_DANCE;
				}
				break;
			case HOW_DANCE:
				actionResponse.addOnlookers(session.getCharacter().getLocation().getCharacters(), "A character dances - " + action);
                actionResponse.setActingCharacterDescription("You dance - " + action);
				break;
			default:
				break;
		}
        
        return actionResponse;
    }
	
    public ActionResponse getActionResponse() {
		return actionResponse;
	}
    
    public Set<String> getKeywords() {
        return keywords;
    }
}